package beans.impl;

import beans.EuroConverter;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;

/**
 * Interface d'administration
 * @author M2 MIAGE Apprentissage - Groupe 3 (VAlbiser)
 */
public class EuroConverterBean implements EuroConverter {

    public double convertToEuro(double amount, String currencySymbol) {
        double taux = getTaux(currencySymbol);
        double result = amount / taux;

        //2 décimales
        int tmp = (int) Math.round(result * 100);

        return tmp/100;
    }

    public double convertFromEuro(double amount, String currencySymbol) {
        double taux = getTaux(currencySymbol);
        double result = amount * taux;

        //2 décimales
        int tmp = (int) Math.round(result * 100);

        return tmp/100;
    }

    public ArrayList<String> getCurrencySymbols() {
        ArrayList<String> currencySym = new ArrayList<String>();

        currencySym.add(new String("EUR"));
        currencySym.add(new String("FRF"));
        currencySym.add(new String("DEM"));
        currencySym.add(new String("ATS"));
        currencySym.add(new String("BEF"));
        currencySym.add(new String("ESP"));
        currencySym.add(new String("ITL"));
        currencySym.add(new String("IEP"));
        currencySym.add(new String("NLG"));
        currencySym.add(new String("PTE"));
        currencySym.add(new String("FIM"));
        currencySym.add(new String("GRD"));

        return currencySym;
    }

    public String getCurrencyRealName(String currencySymbol) {
        Map<String,String> table = new HashMap<String, String>();

        table.put("EUR", "euro");
        table.put("FRF", "franc français");
        table.put("DEM", "mark allemand");
        table.put("ATS", "schilling autrichien");
        table.put("BEF", "franc belge/lux.");
        table.put("ESP", "peseta espagnole");
        table.put("ITL", "lire italienne");
        table.put("IEP", "livre irlandaise");
        table.put("NLG", "florin hollandais");
        table.put("PTE", "escudo portugais");
        table.put("FIM", "mark finlandais");
        table.put("GRD", "drachme grec");

        String currency = table.get(currencySymbol);

        return currency;
    }

    public double getTaux(String currencySymbol){
        Map<String,Double> table = new HashMap<String, Double>();

        table.put("EUR", new Double(1));
        table.put("FRF", new Double(6.55957));
        table.put("DEM", new Double(1.95583));
        table.put("ATS", new Double(13.7603));
        table.put("BEF", new Double(40.3399));
        table.put("ESP", new Double(166.386));
        table.put("ITL", new Double(1936.27));
        table.put("IEP", new Double(0.787564));
        table.put("NLG", new Double(2.20371));
        table.put("PTE", new Double(200.482));
        table.put("FIM", new Double(5.94573));
        table.put("GRD", new Double(340.75));

        double currency = table.get(currencySymbol);

        return currency;
    }

}
